package com.example.firstprojectnew.controller;

import com.example.firstprojectnew.common.WrapMapper;
import com.example.firstprojectnew.common.Wrapper;
import com.example.firstprojectnew.entity.Course;
import com.example.firstprojectnew.entity.User;
import com.example.firstprojectnew.service.CourseService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: lihua
 * @Date: 2025/4/3 14:12
 * @Version: v1.0.0
 * @Description:
 **/
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private CourseService courseService;


    @PostMapping("/select")
    public Wrapper select(@RequestParam String courseId, HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("user");
        Course course = courseService.getCourseById(courseId);

        if(user == null || course == null){
            return WrapMapper.error("用户或者课程不存在!");
        }else {
            return courseService.select(user,course);
        }

    }


}
